package com.ray.ba.code.generator.api.dto;

import com.ray.ba.starter.code.generator.util.DbUtil;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Data;

import javax.sql.DataSource;

/**
 * DbConnectProperty
 *
 * @author ray
 * @date 2020/5/7
 */
@Data
public class DbConnectionProperty {
    public static final String DATABASE_PROTOCOL_MYSQL ="jdbc:mysql://";

    // host:port/db
    private String url;

    private String username;

    private String password;

    public HikariDataSource buildDataSource(){
        String jdbcUrl = DATABASE_PROTOCOL_MYSQL + this.url + "?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
        return DbUtil.getDataSource(jdbcUrl, this.username, this.password);
    }

}
